package IC.Types;

/**
 * Created by IntelliJ IDEA.
 * User: nimrod
 * Date: 09/01/12
 * Time: 15:28
 * To change this template use File | Settings | File Templates.
 */
public class MethodType extends Type {
    private Type[] parameterTypes;
    private Type returnType;


    public MethodType(Type[] parameterTypes, Type returnType, String methodTypeName) {
        super(methodTypeName);
        this.parameterTypes = parameterTypes;
        this.returnType = returnType;
    }
    
    public static String getMethodTypeName(Type[] parameterTypes, Type returnType) {
        StringBuilder sb = new StringBuilder("{");
        String sep = "";
        for (Type param : parameterTypes) {
            sb.append(sep);
            sb.append(param.getName());
            sep = ", ";
        }

        sb.append(" -> ");
        sb.append(returnType.getName());
        sb.append("}");

        return sb.toString();
    }

    @Override
    public boolean subtypeOf(Type t) {
        return false;
    }

    @Override
    public boolean isReferenceType() {
        return false;
    }

    public Type[] getParameterTypes() {
        return parameterTypes;
    }

    public Type getReturnType() {
        return returnType;
    }

    @Override
    public String toString() {
        return this.getId() + ": Method type: " + this.getName();
    }
}
